//
//  YXWindowAlertView.m
//  跑跑快销
//
//  Created by 杨潇 on 14-4-18.
//  Copyright (c) 2014年 YX. All rights reserved.
//

#import "YXWindowAlertView.h"

@implementation YXWindowAlertView
static YXWindowAlertView * windowAlert;
static UILabel * showLabel;
- (id)init
{
    self = [super init];
    if (self) {
    }
    return self;
}

+ (id)sharedWindowAlert
{
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        windowAlert = [[YXWindowAlertView alloc] init];
    });
    return windowAlert;
}

- (void)showLableWithTitle:(NSString *)title
{
    static dispatch_once_t once;
    static UIWindow * window;
    if (window == nil) {
        window = [[UIApplication sharedApplication].windows objectAtIndex:0];
    }
    dispatch_once(&once, ^{
        showLabel = [[UILabel alloc] init];
        showLabel.numberOfLines = 0;
        showLabel.lineBreakMode = NSLineBreakByWordWrapping;
        showLabel.font = [UIFont boldSystemFontOfSize:13];
        showLabel.center = CGPointMake(160, [UIScreen mainScreen].bounds.size.height - 70);
        showLabel.textAlignment = NSTextAlignmentCenter;
        showLabel.textColor = [UIColor whiteColor];
        showLabel.backgroundColor = [UIColor blackColor];
        showLabel.alpha = 0;
        [window addSubview:showLabel];
    });
    [window bringSubviewToFront:showLabel];
    CGSize size = [title sizeWithAFont:[UIFont boldSystemFontOfSize:13]];
    showLabel.text = title;
    if (size.width >= (320 - 50)) {
        showLabel.bounds = CGRectMake(0, 0, 320 - 50, (size.height + 10)*2);
    }else{
        showLabel.bounds = CGRectMake(0, 0, size.width + 30, size.height + 10);
    }

    [UIView animateWithDuration:.5 animations:^{
        showLabel.alpha = 1;
    }];
    [self performSelector:@selector(hidden) withObject:nil afterDelay:3];
}

- (void)hidden
{
    [UIView animateWithDuration:.5 animations:^{
        showLabel.alpha = 0;
    }];
}

@end
